import db from '@dfeidao/atom-nodejs/db';
import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import { systemid } from '../atom/config';
interface Message {
	parent_number: string;
	productid: string;
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:app-approval-details/s004,action_id:' + action_id);

	log('Service end path:app-approval-details/s004,action_id:' + action_id);

	const { exec, prepare } = db.query(action_id, session_id, systemid);
	prepare('parent_information', ['phone', 'parent_number', 'parent_name', 'phone'], { parent_number: message.parent_number, productid: message.productid }, 199, 1, [], []);
	const [data] = await exec();
	const [phone] = data.map((v: { phone: string; }) => {
		return { phone: v.phone };
	});

	return {
		data: { data, phone }
	};
}
